#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from dragon.selector import Selector
from pages.strategybar import StrategyBar
from pages.calendar import Calendar
from dragon.page import DraPage


class StockTrackSe:
    # 策略栏

    #
    plateButton=Selector('.flex-align-center','全部板块按钮')
    calendarButton=Selector('.operate-time>div.bkvalue','日历按钮')
    # 排序
    sortButton=Selector('div.sort.box-shadow','排序按钮')
    selectedSortOption=Selector('div.sort-item.blue','已选中的排序选项')
    timeSortOption=Selector('div.plants-select > div > div:nth-child(1)','时间排序选项')
    increaseSortOption=Selector('div.plants-select > div > div:nth-child(2)','涨幅排序选项')
    changeSortOption = Selector('div.plants-select > div > div:nth-child(3)', '资金次数排序选项')
    includeTimeSortOption = Selector('div.plants-select > div > div:nth-child(4)', '纳入时间排序选项')
    # 资金次数
    changeCountButton=Selector('div.money-num.box-shadow','资金次数按钮')
    changeCountOption=Selector('div.el-slider__marks-text','资金次数选项')
    changeCountLeftBall=Selector('div.plants-select >div>div>div>div>div:nth-child(2)','左球')
    changeCountRightBall=Selector('div.plants-select >div>div>div>div>div:nth-child(3)','右球')
    # changeCountRightBall=Selector('div.plants-select >div>div>div>div>div:nth-child(3)>div','右球')
    changeCountStop=Selector('div.plants-select >div>div>div>div>div:nth-child(5)>div','滑动点')
    # 竞流开
    acoButton=Selector('div.jlk.box-shadow','竞流开按钮')
    auctionOption=Selector('xpath=/html/body/div[2]/div[3]/div/div[1]/div[2]/div/div[6]/div','集合竞价选项')
    circulationOption = Selector('xpath=/html/body/div[2]/div[3]/div/div[2]/div[2]/div/div[6]/div', '流通值选项')
    openVolumeOption = Selector('xpath=/html/body/div[2]/div[3]/div/div[3]/div[2]/div/div[6]/div', '开盘量选项')
    auctionRangeOption=Selector('div.plants-select > div > div:nth-child(1) > div.mobile-bottom-select-btn > div','集合竞价范围选项')
    circulationRangeOption=Selector('div.plants-select > div > div:nth-child(2) > div.mobile-bottom-select-btn > div','流通值范围选项')
    openVolumeRangeOption=Selector('div.plants-select > div > div:nth-child(3) > div.mobile-bottom-select-btn > div','开盘量范围选项')
    auctionLeftBall=Selector('div.plants-select >div>div:nth-child(1)>div>div>div:nth-child(2)','集合竞价左球')
    auctionRightBall=Selector('div.plants-select >div>div:nth-child(1)>div>div>div:nth-child(3)','集合竞价右球')
    circulationLeftBall=Selector('div.plants-select >div>div:nth-child(2)>div>div>div:nth-child(2)','流通值左球')
    circulationRightBall=Selector('div.plants-select >div>div:nth-child(2)>div>div>div:nth-child(3)','流通值右球')
    openVolumeLeftBall=Selector('div.plants-select >div>div:nth-child(3)>div>div>div:nth-child(2)','开盘量左球')
    openVolumeRightBall=Selector('div.plants-select >div>div:nth-child(3)>div>div>div:nth-child(3)','开盘量右球')
    # 标签
    labelButton=Selector('text=选择标签 ','选择标签按钮')
    labelOption=Selector('div.labels-item>div','标签选项')
    selectedLabelOption=Selector('div.labels-item>div.active','已选中的标签选项')
    labelDesc=Selector('div.label-des','标签说明')
    resetButton=Selector('div.mobile-reset','重置按钮')
    confirmButton=Selector('div.mobile-sure','确定按钮')
    labelShortcut=Selector('div.labelOut.df > div > div.labelOut-item-name.df','便签快捷按钮')
    # 股票列表
    stockBlock = Selector('li.infinite-list-item', '股票块')
    stock=Selector('div.demo6-item-name>div','股票')
    stockCode=Selector('div.demo6-item-name>div>span','股票代码')
    changeCount=Selector('div.demo6-item-moneyNum>span','异动次数')
    changeTime=Selector('div.demo6-item-BkName>span','异动时间')
    realtimeIncrease=Selector('div.demo6-shishi>div','实时涨幅')
    changeIncrease=Selector('div.demo-yidong>div','异动涨幅')

    changeDetailButton=Selector('text=资金详情','资金详情按钮')
    clickableChangeDetailButton = Selector(
        'div.demo6-item-right>div.date-right[style="color: rgb(65, 109, 249);"]', '可点击的资金详情按钮')
    changeDetailBlock = Selector('.item-detil', '资金详情栏')
    changeDetailTime=Selector('div.detil-item-time','资金详情时间')
    auction=Selector('div.jlk>div:nth-child(1)>div','集合竞价')
    circulation=Selector('div.jlk>div:nth-child(2)>div','流通值')
    openVolume=Selector('div.jlk>div:nth-child(3)>div','集合竞价')
    labelBar=Selector('div.labels','标签栏')
    label=Selector('div.labels>div','标签')
    notMatchAlert=Selector('div.emptySelect-title','空数据提示')
    notTradeTimeAlert=Selector('div.emptyTime-title','非交易时间提示')
    labelDescFloat=Selector('div.FlotItem','股票说明浮窗')
    includeTime=Selector('div.naru','纳入时间')
    # 广告
    adFloat=Selector('div.AdvertisingBox','广告浮窗')
    adCloseButton=Selector('div.AdvertisingBox-close','关闭广告按钮')


class StockTrackPage(StrategyBar):
    def __init__(self, draPage: DraPage):
        self.draPage = draPage
        super().__init__(draPage)
        self.plateButton = draPage.locator(StockTrackSe.plateButton)
        self.calendarButton = draPage.locator(StockTrackSe.calendarButton)
        self.sortButton = draPage.locator(StockTrackSe.sortButton)
        self.selectedSortOption = draPage.locator(StockTrackSe.selectedSortOption)
        self.timeSortOption = draPage.locator(StockTrackSe.timeSortOption)
        self.increaseSortOption = draPage.locator(StockTrackSe.increaseSortOption)
        self.changeSortOption = draPage.locator(StockTrackSe.changeSortOption)
        self.includeTimeSortOption = draPage.locator(StockTrackSe.includeTimeSortOption)
        self.changeCountButton = draPage.locator(StockTrackSe.changeCountButton)
        self.changeCountOption = draPage.locator(StockTrackSe.changeCountOption)
        self.changeCountLeftBall = draPage.locator(StockTrackSe.changeCountLeftBall)
        self.changeCountRightBall = draPage.locator(StockTrackSe.changeCountRightBall)
        self.changeCountStop = draPage.locator(StockTrackSe.changeCountStop)
        self.acoButton = draPage.locator(StockTrackSe.acoButton)
        self.auctionOption = draPage.locator(StockTrackSe.auctionOption)
        self.circulationOption = draPage.locator(StockTrackSe.circulationOption)
        self.openVolumeOption = draPage.locator(StockTrackSe.openVolumeOption)
        self.auctionRangeOption = draPage.locator(StockTrackSe.auctionRangeOption)
        self.circulationRangeOption = draPage.locator(StockTrackSe.circulationRangeOption)
        self.openVolumeRangeOption = draPage.locator(StockTrackSe.openVolumeRangeOption)
        self.auctionLeftBall = draPage.locator(StockTrackSe.auctionLeftBall)
        self.auctionRightBall = draPage.locator(StockTrackSe.auctionRightBall)
        self.circulationLeftBall = draPage.locator(StockTrackSe.circulationLeftBall)
        self.circulationRightBall = draPage.locator(StockTrackSe.circulationRightBall)
        self.openVolumeLeftBall = draPage.locator(StockTrackSe.openVolumeLeftBall)
        self.openVolumeRightBall = draPage.locator(StockTrackSe.openVolumeRightBall)
        self.labelButton = draPage.locator(StockTrackSe.labelButton)
        self.labelOption = draPage.locator(StockTrackSe.labelOption)
        self.selectedLabelOption = draPage.locator(StockTrackSe.selectedLabelOption)
        self.labelDesc = draPage.locator(StockTrackSe.labelDesc)
        self.resetButton = draPage.locator(StockTrackSe.resetButton)
        self.confirmButton = draPage.locator(StockTrackSe.confirmButton)
        self.labelShortcut = draPage.locator(StockTrackSe.labelShortcut)
        self.stockBlock = draPage.locator(StockTrackSe.stockBlock)
        self.stock = draPage.locator(StockTrackSe.stock)
        self.stockCode = draPage.locator(StockTrackSe.stockCode)
        self.changeCount = draPage.locator(StockTrackSe.changeCount)
        self.changeTime = draPage.locator(StockTrackSe.changeTime)
        self.realtimeIncrease = draPage.locator(StockTrackSe.realtimeIncrease)
        self.changeIncrease = draPage.locator(StockTrackSe.changeIncrease)
        self.changeDetailButton = draPage.locator(StockTrackSe.changeDetailButton)
        self.changeDetailBlock = draPage.locator(StockTrackSe.changeDetailBlock)
        self.clickableChangeDetailButton = draPage.locator(StockTrackSe.clickableChangeDetailButton)
        self.changeDetailTime = draPage.locator(StockTrackSe.changeDetailTime)
        self.auction = draPage.locator(StockTrackSe.auction)
        self.circulation = draPage.locator(StockTrackSe.circulation)
        self.openVolume = draPage.locator(StockTrackSe.openVolume)
        self.labelBar = draPage.locator(StockTrackSe.labelBar)
        self.label = draPage.locator(StockTrackSe.label)
        self.notMatchAlert = draPage.locator(StockTrackSe.notMatchAlert)
        self.notTradeTimeAlert = draPage.locator(StockTrackSe.notTradeTimeAlert)
        self.labelDescFloat = draPage.locator(StockTrackSe.labelDescFloat)
        self.includeTime = draPage.locator(StockTrackSe.includeTime)
        self.adFloat = draPage.locator(StockTrackSe.adFloat)
        self.adCloseButton = draPage.locator(StockTrackSe.adCloseButton)

    def pick_date_by_index(self, index: int):
        self.calendarButton.click()
        calendar = Calendar(self.draPage)
        calendar.pick_date_by_index(index)









